package com.example.iotmanagerment26.controller;

import com.example.iotmanagerment26.domain.*;
import com.example.iotmanagerment26.service.TestService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/test")
@Tag(name="测试用途",description = "ccy测试的接口")
public class TestController {

    @Autowired
    TestService testService;

    @GetMapping("/randomData")
    public JsonData randomData() {
        CcyData ccyData = testService.randomData();
        if (ccyData!=null) {
            return new JsonData(1,ccyData,"查询成功");
        }else {
            return new JsonData(0,ccyData,"查询失败");
        }
    }

    @GetMapping("/temperatureListData")
    public JsonData temperatureListData() {
        List<Integer> list = new ArrayList<>();
        List<String> time = new ArrayList<>();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        // 获取当前时间
        Calendar calendar = Calendar.getInstance();
        for (int i = 0; i < 5; i++) {
            list.add(new Random().nextInt(60)+1);
            String format = formatter.format(calendar.getTime());
            time.add(format);
            calendar.add(Calendar.SECOND, 1);
        }
        return new JsonData(1,new DataInfo(list,time),"查询成功");
    }

    @GetMapping("/humidityListData")
    public JsonData humidityListData() {
        List<Integer> list = new ArrayList<>();
        List<String> time = new ArrayList<>();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        // 获取当前时间
        Calendar calendar = Calendar.getInstance();
        for (int i = 0; i < 5; i++) {
            list.add(new Random().nextInt(80)+1);
            String format = formatter.format(calendar.getTime());
            time.add(format);
            calendar.add(Calendar.SECOND, 1);
        }
        return new JsonData(1,new DataInfo(list,time),"查询成功");
    }

    @GetMapping("/ccydata1")
    public JsonData ccydata1() {
        float wd = new Random().nextFloat(60)+1;
        DecimalFormat df = new DecimalFormat("#.00");
        String formattedWd = df.format(wd);
        wd = Float.parseFloat(formattedWd);

        float sd = new Random().nextFloat(80)+1;
        formattedWd = df.format(sd);
        sd = Float.parseFloat(formattedWd);

        int gz = new Random().nextInt(2000)+1;
        int hwds = new Random().nextInt(2);
        String zsd = new Random().nextInt(3)==0?"On":"Off";
        return new JsonData(1,new CcyData1(wd,sd,gz,hwds,zsd),"查询成功");
    }

    @GetMapping("/ccydata2")
    public JsonData ccydata2() {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        return new JsonData(1, new CcyData2(formatter.format(new Date()),new Random().nextInt(100)+1),"查询成功");
    }

    @GetMapping("/ccydata3")
    public JsonData ccydata3() {
        int i = new Random().nextInt(2);
        return new JsonData(i,i==1?new CcyData3("张三","男",18,"在打工！"):null,"查询成功");
    }
}
